{{ extend './_layouts/home.html' }}

{{ block 'title' }}{{ '博客首页' }}{{ /block }}

{{ block 'body' }} 
<section class="container">
    <div class="col-md-9">
        <div class="bg3Color">
            <div class="user_header">
                <ul class="index-list">
                    <span style="display: none;" id="myTab">{{tab}}</span>
                    <li><a id="index0" href="?tab=all">全部</a></li>
                    <li><a id="index1" href="?tab=share">分享</a id="index0"></li>
                    <li><a id="index2" href="?tab=ask">问答</a id="index0"></li>
                    <li><a id="index3" href="?tab=job">招聘</a id="index0"></li>
                    <li><a id="index4" href="?tab=test">测试</a id="index0"></li>
                </ul>    
            </div>
            <div class="topic-list-container">
                <ul class="topic-list" id="listInfo">
                    {{ each data }}
                    <li class="topic-list-item">
                        <div class="topic-useInfo">
                            <a href="/settings/{{$value.users[0].nickname}}" class="avatar" title="{{$value.users[0].nickname}}">
                                <img src="{{$value.users[0].avatar}}" alt="">
                            </a>
                            <div class="topic_heart">
                                <a href="/topic/show/{{ formateId($value._id) }}" class="topic_title" title="{{data.title}}">{{$value.title}}</a>
                                <div>
                                    <span class="tagOne"><i>{{$value.type}}</i></span>
                                    <span class="cell">
                                        <span class="call_num" title="评论数"><i class="layui-icon layui-icon-dialogue"></i> {{$value.call_num}}</span>
                                        <span class="click_num" title="浏览数"><i class="layui-icon layui-icon-read"></i> {{$value.click_num}}</span>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <span class="pullme-right beforeTime">{{fromNowFormat($value.created_time)}}</span>
                    </li>
                    {{ /each }}
                </ul>
                <div class="pagehelper">
                    <div id="demo1"></div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="bg3Color">
            {{ if user }}
            <div class="user_header">
                <ul class="breadcrumb">
                    <li>个人信息</li>
                </ul>
            </div>
            <div class="user-info">
                <a href="/settings/{{user.nickname}}" class="user-avatar">
                    <img src="{{ user.avatar }}" alt="">
                </a>
                <a href="/settings/{{user.nickname}}" class="user-nickname">{{ user.nickname }}</a>
                <div class="score">
                    <span>积分：{{ user.score }}</span>
                </div>
                <div class="bio">
                    <span>" {{ user.bio }} "</span>
                </div>
            </div>
            {{ else }}
            <div class="user_header">
                <ul class="breadcrumb">
                    <li>Node.js专业中文社区</li>
                </ul>
            </div>
            <div class="user-info">
                <span>您可以
                    <a class="mylink" href="/login">登录</a> 或
                    <a class="mylink" href="/register">注册</a class="mylink">
                </span>
            </div>
            {{ /if }}
        </div>
    </div>
</section>
{{ /block }}
{{ block 'script' }}
<script>
$(function () {
    // 为类别列表添加样式
    for (let i=1;i<5;i++) {
        if ($('#myTab').text() == $('#index' + i).attr('href').split('=')[1]) {
            $('#index' + i).addClass('active')
        } else if ($('#myTab').text() == 'all' || $('#myTab').text().length == 0) {
            $('#index0').addClass('active')
        }
    }
})
layui.use(['laypage', 'layer'], function(){
    var laypage = layui.laypage
    ,layer = layui.layer;      
    //总页数大于页码总数
    laypage.render({
        elem: 'demo1',
        limit: '{{ limit }}',  // 每页显示的条数
        curr: '{{ currentPage || 1 }}',  // 当前页，页面点击
        count: '{{ total }}', //数据总数
        jump: function(obj, first){
            // console.log(obj)
            if (!first) {  //首次不执行
                window.location.href = '?tab={{ tab }}&page=' + obj.curr
            }
        }
    });
});
</script>
{{ /block }}
